package com.game.framework.attrs;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.function.Function;

public class Attrs extends AttrsValue {
    public final int AttrsId;
    public int status;
    private Function<Integer,AttrsValue> globalDataPool;

    public Attrs() {
        super();
        this.AttrsId = 0;
        this.status = Status.NO_INIT.code;
    }

    public Attrs(int AttrsId ,Number value) {
        this.AttrsId = AttrsId;
        this.value = value.doubleValue();
        this.status = Status.INIT_VALUE.code;
    }

    public Attrs globalDataPool(Function<Integer,AttrsValue> obtainWay){
        this.globalDataPool = obtainWay;
        return this;
    }

    private Number value() {
        AttrsValue apply = globalDataPool.apply(this.AttrsId);
        return apply.add(this);
    }

    public static void main(String[] args) {
        Attrs attrs = new Attrs(1, 2);
        System.out.println(attrs.globalDataPool((id) -> new AttrsValue(20)).value());
    }
}

@Getter
@AllArgsConstructor
enum Status{
    NO_INIT(1,"未初始化"),
    INIT_VALUE(2,"初始化数值"),
    INIT_TYPE(3,"初始化类型")

    ;
    public final int code;
    public final String msg;
}
